<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/19 0019
 * Time: 下午 5:13
 */

namespace Admin\Controller;

use Think\Controller;
use Think\Upload;

class AttestationController extends Controller
{
    public function index()
    {
        $list=M("region_list")->where('parent_region_id=1 || parent_region_id=5001')->select();
        $this->assign('list',$list);
        $this->display();
    }

    public function uploadPicture()
    {
        $upload = new Upload();//实例化上传类
        $upload->maxSize = 3145728;//设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');//设置附件上传类型

        $info = $upload->upload();
        if (count($info) < 3) {
            $this->error($upload->getError(), U('Attestation/index'));
        } else {
            $picture = M('picture');
            $id = '';
            foreach ($info as $k => $v) {
                $data = array(
                    'path' => 'Public/Uploads/' . $v['savepath'] . $v['savename'],
                    'md5' => $v['md5'],
                    'sha1' => $v['sha1'],
                    'create_time' => time()
                );
                $id .= $picture->add($data) . ",";
            }
            $id=trim($id,",");
            $arr = I("post.");
            $pic = M('picture')->where("id in($id)")->select();
            $arr['idcard_face'] = $pic[0]['path'];
            $arr['idcard_back'] = $pic[1]['path'];
            $arr['business_license'] = $pic[2]['path'];
            $re = M("supplier_list")->add($arr);
            if($re){
                $this->success('提交成功，审核通过方可登录',U('Login/index'),3);
            }else{
                $this->success('提交失败，请重新提交申请',U('Attestation/index'),3);
            }
        }
    }
    public function region(){
        $id=I("post.id");
        $arr=M("region_list")->field('')->where('parent_region_id='.$id)->select();
        $this->ajaxReturn($arr,'JSON');
    }
}